// 嵌入 App 的 HTML5 页面，如果和 App 有交互，需要加载此文件
var bt_show_bottom_bar;  // 'YES' or 'NO'
var cnl_webview; // iOS WebView close button '1' or '0' 
var shr_flag; // iOS WebView share button '1' or '0'
var _breadtrip_header_list;
var _breadtrip_on_page_leave;  // {'zh': '您确定要退出购买流程，返回首页吗？',
                               //  'en': 'Are you sure to cancel the purchasing?'}

var btAppSchema = {
    versionCompare: function (a,b){var c,d,e,f=/(\.0)+[^\.]*$/;for(a=(a+"").replace(f,"").split("."),b=(b+"").replace(f,"").split("."),e=Math.min(a.length,b.length),c=0;e>c;c++)if(d=parseInt(a[c],10)-parseInt(b[c],10),0!==d)return d;return a.length-b.length;},
    gteVersion: function (a,b){return this.versionCompare(a,b)>=0;}, // a 大于等于 b
    ltVersion: function (a,b){return this.versionCompare(a,b)<0;}, // a 小于 b
    w: $('body').width(),
    h: $(window).height(),
    user_agent: parseInt($('body').attr('data-user-agent'), 10),
    // 0.default 1.iPhone 2.iPad 3.iPod 4.Android
    appVersion: $('body').attr('data-version').replace(/[\[\]']+/g,'').split("_", 2)[1],
    popupDownload: '<div id="popup-download-mask" style="display: none; width: 100%; height: 100%; position: fixed; top: 0; left: 0; background: rgba(0, 0, 0, 0.4); z-index: 999;"></div>' +
            '<div id="popup-download" style="display: none; background:#FBF7ED; position: fixed; z-index: 1000; left: 15px; padding-top: 19px; top: 0; text-align: left;">' +
            '<p id="popup-download-title" style="color: #50BDCB; font-size: 18px; border-bottom: 1px solid #50BDCB; padding-bottom: 7px; line-height: 1.2; margin: 0 15px;">升级提醒</p>'+
            '<p id="popup-download-content" style="color: #5c5c5c; font-size: 18px; line-height: 1; margin: 20px 15px;">您的面包旅行App版本较低，无法观看视频。请升级后，观看视频，并获得更好的使用体验。</p>' +
            '<p style="background: #49BDCC; border-bottom: 3px solid #2D9DAA; padding: 8px 0; text-align: center;">' +
                '<a id="popup-download-cancel" href="###" style="display: inline-block; height: 24px; line-height: 24px; color: #FFF; text-decoration: none; font-size: 18px; width: 49%; border-right: 1px solid #2D9DAA;">知道了</a>' +
                '<a id="popup-download-ok" href="http://breadtrip.com/download/" style="display: inline-block; height: 24px; line-height: 24px; color: #FFF; text-decoration: none; font-size: 18px; width: 49%;">立即下载</a>' +
            '</p>' +
            '</div>',
    clubActivityListJson: "",
    changeFriendshipCallback: function ( statusCode, friendship ) {
        if (statusCode === 0) {
            alert('有错误发生，请稍后再试。');
        } else {
            //0.已屏蔽该人 1.正常 2.关注中 4.好友 5.已被该人屏蔽
            var obj = $('#friendship');
            switch (friendship) {
                case 1:
                    obj.attr('href', obj.data('followuser'));
                    obj.find('b').text('加关注');
                    obj.show();
                    break;
                case 2:
                    obj.attr('href', obj.data('jumptouser'));
                    obj.find('b').text('已关注');
                    obj.addClass('following');
                    obj.show();
                    break;
                case 4:
                    obj.attr('href', obj.data('jumptouser'));
                    obj.find('b').text('好友');
                    obj.addClass('follow-friend');
                    obj.show();
                    break;
                default:
                    obj.hide();
                    break;
            }
        }
    },
    followUser: function( userId ) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法关注，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法关注，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法关注，请下载更新后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = 'app:follow:' + userId;
                } else if ( this.user_agent === 4 ) {
                    android.addFollowings(userId);
                }
            }
        } else {
            window.location.href = "/u/" + userId;
        }
    },
    jumpToUser: function( userId, userName)  {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法打开用户的个人主页，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法打开用户的个人主页，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法打开用户的个人主页，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = 'app:jump:user:' + userId;
                } else if ( this.user_agent === 4 ) {
                    android.startUserInfoActivity(parseInt(userId, 10), userName);
                }
            }
        } else {
            window.location.href = "/u/" + userId;
        }
    },
    jumpToTrip: function(tripId) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看游记，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看游记，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看游记，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = 'app:jump:trip:' + tripId;
                } else if ( this.user_agent === 4 ) {
                    android.startBrowseTripActivity(tripId);
                }
            }
        } else {
            window.location.href = "/trips/" + tripId;
        }
    },
    jumpToTripComment: function(tripId) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.2.0') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看游记评论，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看游记评论，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看游记评论，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 2 ) {
                    window.location.href = 'app:jump:trip:' + tripId + ':comment';
                } else if ( this.user_agent === 4 ) {
                }
            }
        } else {
            window.location.href = "/trips/" + tripId;
        }
    },
    jumpToWaypoint: function(tripId, waypointId) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看游记图片，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看游记图片，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看游记图片，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = 'app:jump:trip:' + tripId + ':waypoint:' + waypointId;
                } else if ( this.user_agent === 4 ) {
                    android.startBrowseTripActivity(parseInt(tripId, 10), parseInt(waypointId, 10));
                }
            }
        } else {
            window.location.href = "/trips/" + tripId + "/#wp" + waypointId;
        }
    },
    jumpToWaypointAnomynous: function(tripId, waypointId) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看游记图片，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看游记图片，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看游记图片，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                } else if ( this.user_agent === 4 ) {
                    android.startLoginAndBrowseTrip(parseInt(tripId, 10), parseInt(waypointId, 10));
                }
            }
        } else {
            window.location.href = "/trips/" + tripId + "/#wp" + waypointId;
        }
    },
    commentWaypoint: function(tripId, waypointId) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法评论照片，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法评论照片，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法评论照片，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:jump:trip:" + tripId + ":waypoint:" + waypointId + ':comment';
                } else if ( this.user_agent === 4 ) {
                    android.startCommentActivity(parseInt(tripId, 10), parseInt(waypointId, 10));
                }
            }
        } else {
            window.location.href = "/trips/" + tripId + "/?extend_comment=" + waypointId + "#wp" + waypointId;
        }
    },
    jumpToDestination: function(destName, destId, destType) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:jump:place:destination/place/" + destType + "/" + destId;
                } else if ( this.user_agent === 4 ) {
                    android.startSpotActivitiy(destName, destId, destType);
                }
            }
        } else {
            window.location.href = "/tinysites/sites/" + destType + "/" + destId;
        }
    },
    jumpToDestinationTab: function(destName, destId, destType, tabTag) {
        /*
        var TAG_OVERVIEW = "overview";
        var TAG_PHOTOS = "photos";
        var TAG_TRIPS = "trips";
        var TAG_TIPS = "tips";
        var TAG_FEED = "feed";
        iOS 3.5.0 / Android 3.4.0 新增 map, places
        iOS 3.6.0 / Android 3.5.0 新增 experience 和  offlinemap
        */
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    if ( this.ltVersion(this.appVersion, '3.3.0') || ((tabTag == 'map' || tabTag == 'places') && this.ltVersion(this.appVersion, '3.5.0')) || ((tabTag == 'experience' || tabTag == 'offlinemap') && this.ltVersion(this.appVersion, '3.6.0')) ) {
                        this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                        // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '暂时忽略');
                    }else{
                        window.location.href = "app:jump:place:destination/place/" + destType + "/" + destId + ":" + tabTag;
                    }
                } else if ( this.user_agent === 4 ) {
                    if ( ((tabTag == 'map' || tabTag == 'places') && this.ltVersion(this.appVersion, '3.4.0')) || ((tabTag == 'experience' || tabTag == 'offlinemap') && this.ltVersion(this.appVersion, '3.5.0')) ) {
                        this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                        // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '暂时忽略');
                    }else{
                        android.startSpotActivity(destName, destId, destType, tabTag);
                    }
                }
            }
        } else {
            window.location.href = "/tinysites/sites/" + destType + "/" + destId;
        }
    },
    jumpToDestinationSubTab: function(destName, destId, destType, tabTag, subTabTag) {
        // 从 iOS 3.3.0 版起弃用
        /*
        var TAG_TRIP = 0;
        var TAG_PHOTO = 1;
        var TAG_LIVE = 2;
        */
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '2.3.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法查看目的地，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:jump:place:destination/place/" + destType + "/" + destId + ":" + tabTag + ":" + subTabTag;
                } else if ( this.user_agent === 4 ) {
                    android.startSpotActivity(destName, destId, destType, tabTag, subTabTag);
                }
            }
        } else {
            window.location.href = "/tinysites/sites/" + destType + "/" + destId;
        }
    },
    jumpToLogin: function(nexturl) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.1.2') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:login";
                } else if ( this.user_agent === 4 ) {
                    android.startLoginActivity();
                }
            }
        } else {
            window.location.href = "/accounts/login/?next="+nexturl;
        }
    },
    jumpToAddTrip: function() {
        if ( this.appVersion ) {
            if ( this.user_agent === 1 || this.user_agent === 2 ) {
                if ( this.ltVersion(this.appVersion, '3.1.0') ) {
                    this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法创建游记，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法创建游记，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                    // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法创建游记，请更新App后再试试。', '暂时忽略');
                } else {
                    window.location.href = "app:edit:trip";
                }
            } else if ( this.user_agent === 4 ) {
                if ( this.ltVersion(this.appVersion, '3.1.2') ) {
                    this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法创建游记，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法创建游记，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                    // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法创建游记，请更新App后再试试。', '暂时忽略');
                } else {
                    android.startTripEditActivity();
                }
            }
        } else {
            window.location.href = "/accounts/login/?next=/";
        }
    },
    getJumpToShareProductViaWeixinParams: function () {
    },
    jumpToShareProductViaWeixin: function(title, content, image, url) {
        this.getJumpToShareProductViaWeixinParams = function() {
            rtn = {"title": title,
                   "content": content,
                   "image_url": image,
                   "product_url": url};
            return JSON.stringify(rtn);
        };
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.1.2') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法分享产品，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法分享产品，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法分享产品，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:share_product_via_weixin:btAppSchema.getJumpToShareProductViaWeixinParams()";
                } else if ( this.user_agent === 4 ) {
                    android.sendGiftToWeixinFriend(title, content, image, url);
                }
            }
        } else {
        }
    },
    jumpToShare: function () {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.1.4') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法分享，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法分享，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法分享产品，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:share";
                } else if ( this.user_agent === 4 ) {
                    android.startShareButton();
                }
            }
        } else {
        }
    },
    jumpToWeb: function(url) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.2.0') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:web:" + url;
                } else if ( this.user_agent === 4 ) {
                }
            }
        } else {
            window.location.href = url;
        }
    },
    jumpToWebView: function (url) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.4.1') ) {
                // this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '暂时忽略');
                window.location.href = url;
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    if ( this.ltVersion(this.appVersion, '3.5.1') ) {
                        // this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                        // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法跳转页面，请更新App后再试试。', '暂时忽略');
                        window.location.href = url;
                    }else{
                        window.location.href = "app:jump:webview:" + url;
                    }
                } else if ( this.user_agent === 4 ) {
                    android.startWebActivity(url);
                }
            }
        } else {
            window.location.href = url;
        }
    },
    jumpToMessage: function (userId) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.2.0') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:message:" + userId;
                } else if ( this.user_agent === 4 ) {
                }
            }
        } else {
            window.location.href = '/messages/talk/' + userId + '/';
        }
    },
    jumpToWxpay: function (oid) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.2.1') ) {
                this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:transaction:wxpay:" + oid;
                } else if ( this.user_agent === 4 ) {
                    android.wxPay(oid);
                }
            }
        } else {
        }
    },
    refreshUser: function () {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.2.0') ) {
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:refresh:user";
                } else if ( this.user_agent === 4 ) {
                }
            }
        } else {
        }
    },
    resetHeight: function (windowheight) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.3.0') ) {
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:ready:resetheight:" + windowheight;
                } else if ( this.user_agent === 4 ) {
                }
            }
        } else {
        }
    },
    showNotification: function (message) {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.4.0') ) {
                // this.showUpdatePopup('升级提醒', '您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '立即下载', '暂时忽略', '升级提醒', '您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '立即下载', '暂时忽略', 'http://breadtrip.com/download/');
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法跳转私信页面，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    window.location.href = "app:notification:" + message;
                } else if ( this.user_agent === 4 ) {
                    android.showToast(message);
                }
            }
        } else {
        }
    },
    showConfirmWindow: function (cntitle, cnmessage, cnconfirm, cncancel, entitle, enmessage, enconfirm, encancel, callback_url, callback_method) {
        // callback_method
        /*
        callback_method(success){} App 返回 success 结果，true or false
        */
        if ( this.appVersion ) {
            console.log(callback_method);
            if ( !callback_method ) { callback_method = ''; }
            console.log(callback_method);
            if ( this.user_agent === 1 ) {
                var _json = {
                    "zhcn":{
                        "title": cntitle,
                        "message": cnmessage,
                        "confirm": cnconfirm,
                        "cancel": cncancel,
                        "callback_url": callback_url,
                        "callback_method": callback_method
                    },"en":{
                        "title": entitle,
                        "message": enmessage,
                        "confirm": enconfirm,
                        "cancel": encancel,
                        "callback_url": callback_url,
                        "callback_method": callback_method
                    }};
                var _jsonToStr = encodeURIComponent(JSON.stringify(_json));
                console.log(_jsonToStr);
                window.location.href = "app:alert:" + _jsonToStr;
            }else if ( this.user_agent === 4 ) {
                if ( callback_method !== '' ) { callback_method = 'javascript:' + callback_method + '(%s)'; }
                android.showDialog(cntitle, cnmessage, cncancel, cnconfirm, callback_url, callback_method);
            }
        }
    },
    hideWebViewLoading: function () {
        if ( this.appVersion ) {
            if ( (this.user_agent === 1 || this.user_agent === 2) && this.gteVersion(this.appVersion, '3.6.0') ) {
                window.location.href = "app:load:finish";
            }else if ( this.user_agent === 4 && this.gteVersion(this.appVersion, '3.5.0') ) {
                android.setProgressDialog(false);
            }
        }
    },
    hideUpdatePopup: function() {
        $('#popup-download').hide();
        $('#popup-download-mask').hide();
    },
    // showUpdatePopup: function(text, cancel_text, ok_text) {
    showUpdatePopup: function(cntitle, cnmessage, cnconfirm, cncancel, entitle, enmessage, enconfirm, encancel, callback_url, callback_method) {
        if ( this.gteVersion(this.appVersion, '3.5.0') ) {
            if (!cancel_text) { cancel_text = '取消'; }
            if (!ok_text) { ok_text = '确定'; }
            if ( this.user_agent === 1 ) {
                this.showConfirmWindow(cntitle, cnmessage, cnconfirm, cncancel, cntitle, cnmessage, enconfirm, encancel, callback_url, callback_method);
            }else if( this.user_agent === 4 ){
                android.showDialog(cntitle, cnmessage, cncancel, cnconfirm, callback_url, callback_method);
            }
        }else{
            if (cncancel) {
                $('#popup-download-cancel').text(cncancel);
            }
            if (cnconfirm) {
                $('#popup-download-ok').text(cnconfirm);
            }
            if (cnmessage) {
                $('#popup-download-content').text(cnmessage);
            }
            $('#popup-download').css({
                width: btAppSchema.w - 30,
                top: (btAppSchema.h - 287)/2
            }).show();
            $('#popup-download-mask').show();
        }
    },
    setClubActivityList: function(json) {
        this.clubActivityListJson = json;
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.1.2') ) {
                this.showUpdatePopup('您未安装最新版本的面包旅行App，无法打开用户的个人主页，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                    // IOS 的会主动调用 btAppSchema.getClubActivityList();
                } else if ( this.user_agent === 4 ) {
                    android.setClubActivityList(json);
                }
            }
        } else {
        }
    },
    getClubActivityList: function() {
        return this.clubActivityListJson;
    },
    onPageLoad: function() {
        if ( this.appVersion ) {
            if ( this.ltVersion(this.appVersion, '3.1.1') ) {
                // this.showUpdatePopup('您未安装最新版本的面包旅行App，无法打开用户的个人主页，请更新App后再试试。', '暂时忽略');
            } else {
                if ( this.user_agent === 1 || this.user_agent === 2 ) {
                } else if ( this.user_agent === 4 ) {
                    if(typeof(android) == "undefined") {
                    } else {
                        if ( this.gteVersion(this.appVersion, '3.3.1') && ( cnl_webview == 1 ) ) {
                            android.showHomeButton(true);
                        }
                        android.setTitle(breadtrip_banner_title);
                        android.setTitleListView(_breadtrip_header_list);
                        if(shr_flag == 1) {
                            android.loadShareButton(shr_text,
                                shr_photo,
                                shr_title,
                                shr_summary,
                                shr_image,
                                shr_wechat_title_friend,
                                shr_wechat_summary_friend,
                                shr_wechat_title_circle,
                                shr_wechat_summary_circle,
                                shr_wechat_image);
                        }
                        if(_breadtrip_on_page_leave) {
                            android.onBackPressed(
                                true, _breadtrip_on_page_leave['zh']
                            );
                        }
                    }
                }
            }
        } else {
        }
    },
    breadtrip_back: function(lang) {
        return _breadtrip_on_page_leave[lang];
    }
};

function breadtrip_back(lang) {
    if(_breadtrip_on_page_leave) {
        return btAppSchema.breadtrip_back(lang);
    }
}

function onPageLoad() {
    btAppSchema.onPageLoad();
}

$(document).ready(function() {
    $(btAppSchema.popupDownload).appendTo('body');
    $('body').on('click', '#popup-download-mask, #popup-download-cancel', function() {
        btAppSchema.hideUpdatePopup();
    });
});
